home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekikoh Dennoh Club 1
/
Gekikoh Dennoh Club Vol. 1 (Japan).7z
/
Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin
/
kowin
/
archive
/
apl
/
gview120.lzh
/
gviewsrc.lzh
/
gview.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-02-27
|
7KB
|
291 lines
/*
Copyright 1995 Ogasawara Hiroyuki(COR.)
*/
#include <corlib.h>
#include <sys_doslib.h>
#include "gview.h"
#include "mpat.h"
GVIEW *
MakeRegion( gp )
GVIEW *gp;
{
GVIEW *np= GV_Alloc( gp->rh, gp->rv, gp->color, "", NULL, 0 );
if( gp->color == WindowAttrGraphic65536 ){
unsigned short *str= np->buf,
*ptr= gp->buf+ gp->ry*gp->h+gp->rx;
int y, x;
for( y= 0 ; y< gp->rv ; y++, ptr+= gp->h-gp->rh )
for( x= 0 ; x< gp->rh ; x++ )
*str++= *ptr++;
}else{
unsigned char *str= (void*)np->buf,
*ptr= ((unsigned char*)gp->buf)+
gp->ry*gp->h+gp->rx;
int y, x;
for( y= 0 ; y< gp->rv ; y++, ptr+= gp->h-gp->rh )
for( x= 0 ; x< gp->rh ; x++ )
*str++= *ptr++;
np->palet= gp->palet;
}
return np;
}
static void
UserSend( wp, info, gp )
WindowID wp;
EventInfo *info;
GVIEW *gp;
{
WindowID cwp;
mspatset();
mspat( TRUE );
while( !(WindowGetEventInfo(info) && info->LeftOFF) );
cwp= WindowGetChild( WindowRootID, info );
mspat( FALSE );
if( cwp ){
if( wp && cwp == wp )
return;
info->option= EventUser;
info->ComData= UserGraphic;
if( gp->info == iPOS && (gp->rh < gp->h || gp->rv < gp->v) ){
GVIEW *np= MakeRegion( gp );
(void*)(info->ComBuffer)= np;
WindowSendEvent( cwp, info );
MFREE( np );
return;
}else
(void*)(info->ComBuffer)= gp;
if( !WindowSendEvent( cwp, info ) ){
info->option= EventUser;
info->ComData= UserString;
(void*)(info->ComBuffer)= gp->fname;
WindowSendEvent( cwp, info );
}
}
}
static void
SetPalet( gp )
GVIEW *gp;
{
unsigned short *pal= gp->palet;
if( pal ){
int i, count= GV_PaletSize( gp->color );
for( i= 0 ; i < count ; i++ )
GPALET( i, *pal++ );
}
}
#define XP 2
#define YP 2
#define FONT 12
static char *
numform( str, i, len )
char *str;
{
char *p= str;
str+= len;
do{
*--str= i%10 +'0';
}while( i/= 10 );
for(; str > p ; *--str= ' ' );
return p+len;
}
static char pbuf[]= "( 0, 0)-( 0, 0)[ 0, 0]";
static
PutInfo( dp, gp, mode )
DrawBuf *dp;
GVIEW *gp;
{
static char sbuf[]= "size ( , )";
int attr= (gp->flag & fSLEEP) ? 9 :
((gp->flag & fICOLOR) ? 10 : 32+1);
switch( mode ){
case 1:
numform( sbuf+6 , gp->h, 4 );
numform( sbuf+11, gp->v, 4 );
DrawSetSymbol( dp++, XP,YP+ 0, gp->fname, attr, FONT );
DrawSetSymbol( dp++, XP,YP+14, sbuf, attr, FONT );
DrawSetSymbol( dp , XP,YP+28, gp->comment, attr, FONT );
return 3;
case 2:
numform( pbuf+1 , gp->rx, 4 );
numform( pbuf+6 , gp->ry, 4 );
numform( pbuf+13, gp->rx+gp->rh-1, 4 );
numform( pbuf+18, gp->ry+gp->rv-1, 4 );
numform( pbuf+24, gp->rh, 4 );
numform( pbuf+29, gp->rv, 4 );
case 20:
DrawSetSymbol( dp++, XP,YP+ 0, pbuf, attr, FONT );
return 1;
}
return 0;
}
static
PosChk( x, h )
{
if( x < 0 )
return 0;
if( x >= h )
return h-1;
return x;
}
static
SetPos( wp, info, gp )
WindowID wp;
EventInfo *info;
GVIEW *gp;
{
int attr= (gp->flag & (fSLEEP|fICOLOR)) ? 0 : 3,
bttr= (gp->flag & fSLEEP) ? 1 : 2;
DrawBuf dbuf[3];
int rx, ry, ex= -1, ey= -1, wx, wy;
WindowGetScreenPosition( wp, &rx, &ry );
gp->rx= PosChk( info->x, gp->h );
gp->ry= PosChk( info->y, gp->v );
numform( pbuf+1 , gp->rx, 4 );
numform( pbuf+6 , gp->ry, 4 );
for(; WindowGetEventInfo( info ), info->LeftStat ;){
info->x-= rx;
info->y-= ry;
if( info->x != ex || info->y != ey ){
DrawSetLine( dbuf, gp->rx, gp->ry, ex, ey,
bttr, OptionBox );
numform( pbuf+13, ex= PosChk( info->x, gp->h ), 4 );
numform( pbuf+18, ey= PosChk( info->y, gp->v ), 4 );
if( (wx= ex-gp->rx) < 0 ) wx= -wx;
if( (wy= ey-gp->ry) < 0 ) wy= -wy;
numform( pbuf+24, ++wx, 4 );
numform( pbuf+29, ++wy, 4 );
PutInfo( dbuf+1, gp, 20 );
DrawSetLine( dbuf+2, gp->rx, gp->ry, ex, ey,
attr, OptionBox );
WindowDraw( wp, dbuf, 3 );
}
}
if( ex >= 0 ){
DrawSetLine( dbuf, gp->rx, gp->ry, ex, ey, bttr, OptionBox );
if( gp->rx > ex ) gp->rx= ex;
if( gp->ry > ey ) gp->ry= ey;
gp->rh= wx;
gp->rv= wy;
PutInfo( dbuf+1, gp, gp->info );
WindowDraw( wp, dbuf, 2 );
}
}
static void
ClrInfo( gp )
GVIEW *gp;
{
int attr= (gp->flag & fSLEEP) ? ColorGray : ColorGraphic;
char buf[80];
DrawBuf dbuf[1];
WindowDraw( gp->wp, dbuf, GposSetClear( gp->wp, dbuf, attr,
ColorGray ) );
}
static int
EventExec( wp, info )
WindowID wp;
EventInfo *info;
{
DrawBuf dbuf[10], *dp;
GVIEW *gp= WindowGetClientPointer( wp );
switch( info->option ){
case EventOpen:
WindowSetEventAttr( wp, EventOpenON|EventRedrawON
|EventCloseON|EventMouseSwitchON|EventPopON
|EventMoveON|EventGraphicON|EventIconifyON
|EventUserON );
return TRUE;
case EventIconify:
WindowSetAttr( wp, 0 );
IconEnt( wp, *gp->fname ? gp->fname : "Gview",
AttrDefault, 12 );
return TRUE;
case EventRedraw:
if( gp->flag & fSLEEP ){
DrawSetClear( dbuf, ColorGray );
WindowDraw( wp, dbuf,
PutInfo( dbuf+1, gp, gp->info)+1 );
}else{
DrawBuf *dp= dbuf;
WindowSetAttr( gp->wp, gp->color );
SetPalet( gp );
dp+= GposSetClear( wp, dp,
ColorGraphic, ColorGray );
dp+= PutInfo( dp, gp, gp->info );
DrawSetGraphicPut( dp++, 0, 0,
gp->h-1, gp->v-1, (short*)gp->buf );
WindowDraw( wp, dbuf, dp-dbuf );
}
return TRUE;
case EventClose:
WindowClose( wp );
if( gp )
MFREE( gp );
return TRUE;
case EventUser:
return TRUE;
case EventPop:
case EventMove:
if( gp->flag & fSLEEP ){
gp->flag= !fSLEEP;
WindowSetGraphicMode( gp->color );
SetPalet( gp );
}
return GposPopAndMove( wp, info );
case EventGraphic:
if( info->x == gp->color && (gp->flag & fSLEEP) ){
gp->flag&=~fSLEEP;
WindowRedraw( wp );
}else if( info->x!= gp->color && !(gp->flag & fSLEEP)){
gp->flag|= fSLEEP;
WindowRedraw( wp );
}
return TRUE;
case EventMouseSwitch:
if( gp->info == iPOS && info->LeftStat &&
(info->ShiftStat & 4) ){
SetPos( wp, info, gp );
}else if( info->LeftON ){
UserSend( wp, info, gp );
}else if( info->RightON ){
gp->info= (gp->info+1) % iLAST;
if( gp->info ){
ClrInfo( gp );
WindowDraw( wp,dbuf,
PutInfo( dbuf, gp, gp->info) );
}else{
ClrInfo( gp );
gp->flag^= fICOLOR;
}
}
return TRUE;
}
return FALSE;
}
void
GV_Open( x, y, gp )
GVIEW *gp;
{
gp->wp= WindowTitleOpen( x, y, gp->h, gp->v, NULL, "GraphicView",
Close|Push|Icon, EventExec );
WindowSetClientData( gp->wp, 0, gp );
WindowSetGraphicMode( gp->color );
GposInit( gp->wp );
WindowRedraw( gp->wp );
}